<?php


namespace App\Services\Questions\Type;


use App\Models\Question;
use App\Services\Questions\BaseQuestion;
use Illuminate\Http\Request;

class Short extends BaseQuestion
{
    /**
     * 简答题的store方法
     *
     * @param Request $request
     * @return mixed|void
     */
    public function store(Request $request)
    {
        // 验证规则
        $request->validate($this->validate($request));

        // 增加需要的字段
        $request->offsetSet('user_id', auth('api')->id());

        parent::store($request);
    }

    /**
     * 验证规则
     *
     * @param $request
     * @return array|\string[][]
     */
    public function validate($request)
    {
        $request->offsetUnset('answer');

        return [
            'pid' => ['sometimes','exists:questions,id,type,subsystem'],
            'success_answer' => ['required']
        ];
    }

    /**
     * 简答题的update方法
     *
     * @param Request $request
     * @param Question $question
     * @return mixed|void
     */
    public function update(Request $request, Question $question)
    {
        $request->validate($this->validate($request));

        parent::update($request,$question);
    }
}
